package org.lemon.transport.context.data.message;

import lombok.Data;

import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Data
public class MessageMetaData implements Serializable {

    public static final MessageMetaData EMPTY = new MessageMetaData(0);

    private final Map<String, String> data;

    public MessageMetaData() {
        this.data = new ConcurrentHashMap<>();
    }

    public MessageMetaData(Map<String, String> data) {
        this.data = new ConcurrentHashMap<>();
        data.forEach(this::putValue);
    }

    private MessageMetaData(int ignored) {
        this.data = Collections.emptyMap();
    }

    public String getValue(String key) {
        return this.data.get(key);
    }

    public void putValue(String key, String value) {
        if (key != null && value != null) {
            this.data.put(key, value);
        }
    }

    public Map<String, String> values() {
        return new HashMap<>(this.data);
    }

    public MessageMetaData copy() {
        return new MessageMetaData(this.data);
    }
}
